<template>
	<view class="base-info" v-show="goodInfo">
		<view class="title">
			<text>{{ goodInfo.title }}</text>
		</view>
		<view class="price-bar">
			<view class="price" :class="ifHasDiscount">
				<text class="new-price">{{ goodInfo.newPrice }}
					<text class="old-price">
						<del>{{ goodInfo.oldPrice }}</del>
					</text>
				</text>
				<view v-show="goodInfo.discount" class="discount">
					{{ goodInfo.discount }}
				</view>
			</view>
			<view class="star" @click="collect = !collect">
				<image v-show="collect" src="@/static/img/common/collect.svg" alt="" @click="Uncollect" />
				<image v-show="!collect" src="@/static/img/common/no-collect.svg" alt="" @click="Collect" />
			</view>
		</view>
		<view class="info">
			<text v-for="(item, index) in goodInfo.columns" :key="index">
				{{ item }}
			</text>
		</view>
		<view class="guarantee">
			<view class='view' >
				<image class='image' src="@/static/img/common/Guarantee.svg" alt="" /> <text>退货补运费</text>

			</view>
			<view class='view' >
				<image class='image' src="@/static/img/common/Guarantee.svg" alt="" /><text>全国包邮</text>

			</view>
			<view class='view' >
				<image class='image' src="@/static/img/common/Guarantee.svg" alt="" /><text>7天无忧退货</text>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapState
	} from "vuex";
	export default {
		name: "DetailBaseInfo",
		props: {
			goodInfo: {
				type: Object,
				default () {
					return {};
				},
			},
			goodId: {
				type: String,
				default () {
					return "";
				},
			},
			shopId: {
				type: String,
				default () {
					return "";
				},
			},
			goodObj: {
				type: Object,
				default () {
					return {};
				},
			},
		},
		data() {
			return {
				defaultServices: ["退货补运费", "全国包邮", "7天无忧退货"],
				collect: false,
			};
		},
		created() {
			this.collect = this.goodIfCollected(this.goodId);
		},
		computed: {
			...mapGetters(["goodIfCollected"]),
			...mapState(["isLogin"]),
			ifHasDiscount() {
				return this.goodInfo.discount ? "price-discount" : "";
			},
		},
		methods: {
			...mapMutations(["goodCollected", "goodUnCollect"]),
			Collect() {
				if (this.isLogin) {
					this.goodCollected({
						...this.goodObj
					});

					this.success("收藏成功");
				} else {
					uni.navigateTo({
						url: "/pages/user/Login"
					})
				}
			},

			Uncollect() {
				this.success("取消收藏");
				this.goodUnCollect(this.goodId);
			},
		},

	};
</script>
<style lang="scss" scoped>
	.base-info {
		width: 100%;

		.title {
			color: black;
			font-size: 38rpx;
			margin: 10rpx 0 20rpx;
		}

		.price-bar {
			color: deeppink;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.price-discount {
				border-bottom: 10rpx solid deeppink;
			}


			.price {
				display: flex;
				justify-content: space-between;
				/* #ifdef H5 */
				gap: 20rpx;
				/* #endif */

				.new-price {
					font-size: 40rpx;
					padding-left: 28rpx;

					.old-price {
						color: grey;
						font-size: 30rpx;
					}
				}

				.discount {
					bottom: 0;
					color: white;
					font-size: 36rpx;
					background-color: deeppink;
					border-radius: 20rpx 0 0 0;
					border-bottom: 5px solid deeppink;
					padding: 10rpx 10rpx 0;
				}

			}

			.star {
				padding-right: 30rpx;
				
				image{
					width: 64rpx;
					height: 64rpx;
				}
			}

		}


		.info {
			display: flex;
			justify-content: space-between;
			padding: 10rpx;
			font-size: 0.9rem;
			color: grey;
		}

		.guarantee {
			display: flex;
			justify-content: space-around;
			align-content: center;
			font-size: 34rpx;
			border-top: 2rpx solid rgb(224, 224, 224);
			border-bottom: 6rpx solid rgb(224, 224, 224);
			padding: 20rpx 0px;

			.view {
				display: flex;
				justify-content: center;
				align-items: center;

				.image {
					// content: url("@/static/img/common/none.svg");
					// background: url("@/static/img/common/Guarantee.svg") no-repeat;
					// background-size: 40rpx 40rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}
		}


	}
</style>
